import csv
import matplotlib.pyplot as plt
from datetime import datetime
filename = 'sitka_weather_07-2014.csv'

def switch(numbers):
    '''华氏度转化为摄氏度'''
    c = []
    for number in numbers:
        c_number = (int(number) - 32) * 5//9
        c.append(c_number)
    return c

with open(filename) as file_obj:
    '''读取文件首行'''
    reader = csv.reader(file_obj)
    head_row = next(reader)

    '''获取最高最低温度（华氏度）'''
    highs, lows, dates = [], [], []
    for reader_simple in reader:
        date_simple = datetime.strptime(reader_simple[0], "%Y-%m-%d")
        dates.append(date_simple)
        highs.append(reader_simple[1])
        lows.append(reader_simple[3])
        print(dates)

'''转化为摄氏度'''
highs_c = switch(highs[:])
lows_c = switch(lows[:])

'''转化日期'''


# print(highs_c, lows_c)

'''绘制图表'''
fig = plt.figure(figsize=(16, 9))
plt.plot(dates, highs_c, c='red')
plt.plot(dates, lows_c, c='green')

'''设置图标格式'''
plt.title("July 2014 Daily High-low temperatures")
plt.ylabel('C')
fig.autofmt_xdate()
plt.show()
